<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Awesome-pyecharts</title>
    <script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://assets.pyecharts.org/assets/echarts.min.js"></script>
 
</head>
<body>
    <div id="bar" style="width:600px; height:300px;"></div>
    <script>
        var chart = echarts.init(document.getElementById('bar'), 'white', {renderer: 'canvas'});
        var old_data = [];
        $(
            function () {
                fetchData(chart);
                setInterval(update_line_data, 1000);
            }
        );
 
        function fetchData() {
            $.ajax({
                type: "GET",
                url: "{{url_for('ct.get_line_chart')}}",
                dataType: "json",
                success: function (result) {
                    chart.setOption(result);
                    old_data = chart.getOption().series[0].data;
                }
            });
        }
 
        function update_line_data() {
            $.ajax({
                type: "GET",
                url: "{{url_for('ct.update_line_data')}}",
                dataType: "json",
                success: function (result) {
                    old_data.push([result.name, result.value]);
                    chart.setOption({
                        series: [{data: old_data}]
                    });
                }
            });
        }
 
    </script>
</body>
</html>